/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package analizadorlexico;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Grupo 4
 */
public class AnalizadorLexico {

    public void Comparacion(String cadena) throws IOException {
        String c = cadena, u = "";
        for (int i = 0; i < c.length(); i++) {
            if ((c.charAt(i) > 64 && c.charAt(i) < 91)
                    || (c.charAt(i) > 96 && c.charAt(i) < 123)) {
                u += 1;
            }
            if (c.charAt(i) == 32) {
                u += " ";
            }
            if (c.charAt(i) > 47 && c.charAt(i) < 58) {
                u += "a";
            }
            if ((c.charAt(i) > 39 && c.charAt(i) < 44) || c.charAt(i) == 45
                    || c.charAt(i) == 47 || (c.charAt(i) == 59 && c.charAt(i) == 63)) {
                u += c.charAt(i);
            }
            if (c.charAt(i) == 59) {
                u += "\n";
            }
        }
        /*try {
            Eliminar();
        } catch (Exception ex) {
            Logger.getLogger(AnalizadorLexico.class.getName()).log(Level.SEVERE, null, ex);
        }*/
        generarArchivo(u);
    }

    public void generarArchivo(String u) throws IOException {
        FileWriter fichero = new FileWriter("Salida.txt", true);
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(fichero);
            pw.print(u);
            pw.println("");
            pw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != fichero) {
                    fichero.close();
                }
                if (null != pw) {
                    pw.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }

    public static void Eliminar() throws Exception {
        try {
            File fichero = new File("Salida.txt");
            if (!fichero.delete()) {
                throw new Exception("El fichero Salida.txt no puede ser borrado!");
            }
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
}
